﻿using System;
using System.Windows;
using Ags.MonsterTools.Common;
using Microsoft.Practices.Unity;

namespace Ags.MonsterTools
{
    public class MainWindowHandler : IMainWindowHandler
    {
        private readonly IUnityContainer _container;

        public MainWindowHandler(IUnityContainer container)
        {
            _container = container;
        }

        public void Show()
        {
            var window = _container.Resolve<MainWindow>();
            window.Show();
            window.WindowState = WindowState.Normal;
            window.Activate();

            OnMainWindowShown(new WindowHandlerEventArgs());
        }

        public void Hide()
        {
            var window = _container.Resolve<MainWindow>();
            window.Hide();

            OnMainWindowHided(new WindowHandlerEventArgs());
        }

        public void Close()
        {
            var window = _container.Resolve<MainWindow>();
            window.Close();
        }

        #region Events

        public event EventHandler OnHidden;

        protected virtual void OnMainWindowHided(WindowHandlerEventArgs e)
        {
            if (OnHidden != null)
                OnHidden(this, e);
        }

        public event EventHandler OnShown;

        protected virtual void OnMainWindowShown(WindowHandlerEventArgs e)
        {
            if (OnShown != null)
                OnShown(this, e);
        }

        #endregion
    }

    public class WindowHandlerEventArgs : EventArgs
    {   
    }
}
